CC = gcc
FLAGS = -Wall -Werror
LINK = -lrt
TESTS = ./files_tests/

all: emulator sender requester
	# Test 1
	- cp -r ./files_source/test1 ./test1
	- cp sender ./test1/sender1
	- cp requester ./test1/requester1
	- cp emulator ./test1/emulator1

	# Test 2
	- cp -r ./files_source/test2 ./test2
	- cp sender ./test2/sender1
	- cp requester ./test2/requester1
	- cp emulator ./test2/emulator1
	- cp emulator ./test2/emulator2

	# Test 3
	- cp -r ./files_source/test3 ./test3
	- cp sender ./test3/sender1
	- cp requester ./test3/requester1
	- cp emulator ./test3/emulator1

	# Test 4
	- cp -r ./files_source/test4 ./test4
	- cp sender ./test4/sender1
	- cp requester ./test4/requester1
	- cp emulator ./test4/emulator1

	# Test 5
	- cp -r ./files_source/test5 ./test5
	- cp sender ./test5/sender1
	- cp requester ./test5/requester1
	- cp emulator ./test5/emulator1

	# Test 6 (move binaries into the files instead of copy)
	- cp -r ./files_source/test6 ./test6
	- mv sender ./test6/sender1
	- mv requester ./test6/requester1
	- mv emulator ./test6/emulator1

# Original Tests
#- cp -r ./files_source/sender1 ./sender1
#- cp -r ./files_source/sender2 ./sender2
#- cp sender sender1
#- mv sender sender2
#- cp -r ./files_source/requester1 ./requester1
#- mv requester requester1
#- rm requester1/hello.txt
#- rm requester1/split.txt

test: test_queue test_rand test_time
	- rm $(TESTS)test_results.txt
	- $(TESTS)test_queue >> $(TESTS)test_results.txt
	- rm $(TESTS)test_queue
	- $(TESTS)test_rand >> $(TESTS)test_results.txt
	- rm $(TESTS)test_rand
	- $(TESTS)test_time >> $(TESTS)test_results.txt
	- rm $(TESTS)test_time
	- cat $(TESTS)test_results.txt

emulator: emulator.c network.h util.h queue.h forward_table.h
	$(CC) $(LINK) $(FLAGS) emulator.c -o emulator

sender: sender.c network.h util.h
	$(CC) $(LINK) $(FLAGS) sender.c -o sender

requester: requester.c network.h util.h
	$(CC) $(LINK) $(FLAGS) requester.c -o requester

# UNIT TESTS
test_queue: $(TESTS)test_queue.c queue.h
	$(CC) $(LINK) $(FLAGS) $(TESTS)test_queue.c -o $(TESTS)test_queue

test_rand: $(TESTS)test_rand.c util.h
	$(CC) $(LINK) $(FLAGS) $(TESTS)test_rand.c -o $(TESTS)test_rand

test_time: $(TESTS)test_time.c util.h
	$(CC) $(LINK) $(FLAGS) $(TESTS)test_time.c -o $(TESTS)test_time

clean:
	- rm -r test1/
	- rm -r test2/
	- rm -r test3/
	- rm -r test4/
	- rm -r test5/
	- rm -r test6/
#	- rm -r sender1/
#	- rm -r sender2/
#	- rm -r requester1/
#	- rm emulator
#	- rm mylog.txt
